package org.example.Server.controller.examination;

import lombok.extern.slf4j.Slf4j;
import org.example.Server.model.examination.ExamSetting;
import org.example.Server.model.examination.TeachExamDTO;
import org.example.Server.service.examination.TeachExamService;
import org.example.Server.utils.ResultAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 教师的在线考试模块
 */
@RestController
@Slf4j
@RequestMapping("/youxich/exam/teacher")
public class TeachExamController {
    @Autowired
    TeachExamService teachExamService;

    /**
     * 使用已有试卷添加在线测试（考试）
     *
     * @param teachExamDTO
     * @return
     */
    @PostMapping("/ready")
    public ResultAPI addReadyPExam(@RequestBody TeachExamDTO teachExamDTO) {
        return teachExamService.addReadyPExam(teachExamDTO);
    }

    /**
     * 添加新试卷！添加在线测试（考试）
     *
     * @param teachExamDTO
     * @return
     */
    @PostMapping("/new")
    public ResultAPI addNewPExam(@RequestBody TeachExamDTO teachExamDTO) {
        return teachExamService.addNewPExam(teachExamDTO);
    }

    /**
     * 获取在线考试列表
     *
     * @param sem_id
     * @param status
     * @return
     */
    @GetMapping
    public ResultAPI getTeachExamList(@RequestParam Integer sem_id, @RequestParam(required = false) Integer status) {
        return teachExamService.getTeachExamList(sem_id, status);
    }

    /**
     * 批量删除考试
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public ResultAPI deleteExams(@PathVariable Integer[] ids) {
        ResultAPI result = null;
        result=teachExamService.deleteExams(ids);
        return result;
    }

    /**
     * 教师设置测试规则（那几个tab全用这一个接口）
     *
     * @param examSetting
     * @return
     */
    @PostMapping("/paper/rule")
    public ResultAPI addPaperRule(@RequestBody ExamSetting examSetting) {
        return teachExamService.addPaperRule(examSetting);
    }

    /**
     * 教师试卷规则回显
     *
     * @param exam_id
     * @return
     */
    @GetMapping("/paper/rule")
    public ResultAPI getPaperRule(@RequestParam Integer exam_id) {
        return teachExamService.getPaperRule(exam_id);
    }


}
